package com.trkj.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.trkj.service.YzrPurchPlanService;
import com.trkj.vo.Result;
import com.trkj.vo.YzrMedPlanVo;
import com.trkj.vo.YzrMedPurchDetVo;
import com.trkj.vo.YzrMedPurchVo;

@Controller
public class YzrPurchPlanController {
	@Autowired
	private YzrPurchPlanService yzrMedPlanService;
	
	//制定采购计划
	@RequestMapping("/to_test")
	public String toDoMedicinePlan(){
		return "yzr_test";
	}
	
	//采购计划管理
	@RequestMapping("/to_medPurchPlan")
	public String toMedPurchPlan(){
		return "yzr_medPurchPlan";
	}

	
	//编辑采购计划
	@RequestMapping("/editPurchPlan")
	public @ResponseBody Result editPurchPlan(String purchId,String purchTitle,
												String purchMakepeople,String purchAutdit,
												Date purchArriivalDate,Date purchZdTime,
												YzrMedPlanVo  medPurchDets){
		
		yzrMedPlanService.editPurchPlan(purchId, purchTitle, purchMakepeople, purchAutdit, purchArriivalDate, 
											purchZdTime, medPurchDets);
		
		return new Result();		
	}
	
	
	//制定采购计划
	@RequestMapping("/doMedPlan")
	public @ResponseBody Result doMedPlan(YzrMedPlanVo medPlanVo){
		System.err.println("controller:"+medPlanVo.getMedPurchDets().size());
		yzrMedPlanService.doMedPlan(medPlanVo);
		return new Result();		 
	}
	

	//分页查询药品采购计划
	@RequestMapping("/queryAllMedPurch")
	public @ResponseBody Map<String, Object> queryAllMedPurch(int page, int rows){
		return yzrMedPlanService.queryAllMedPurch(page, rows);		
	}
	
	//分页查询药品采购明细
	@RequestMapping("/queryAllPurchDet")
	public @ResponseBody Map<String, Object> queryAllPurchDet(int page, int rows,String purchId){
		System.err.println("进入");
		return yzrMedPlanService.queryAllPurchDet(page, rows, purchId);
	}
	
	//根据id查询药品采购明细
	@RequestMapping("/queryAllPurchDet2")
	public @ResponseBody List<YzrMedPurchDetVo> queryAllPurchDet2(String purchId){
		System.err.println("进入");
		return yzrMedPlanService.queryAllPurchDet2(purchId);
	}
	
	//根据采购计划id查找出采购计划和计划明细
	@RequestMapping("/queryAllPlanAndPlanDet")
	public @ResponseBody YzrMedPlanVo queryAllPlanAndPlanDet(String purchId){
		return yzrMedPlanService.queryAllPlanAndPlanDet(purchId);	
	}
	
	//返回根据采购计划id查找出的计划明细的条数
	@RequestMapping("/queryPlanDetCount")
	public  @ResponseBody  long queryPlanDetCount(String purchId){
		return yzrMedPlanService.queryPlanDetCount(purchId);		
	}
	
	//根据id查找采购计划
	@RequestMapping("/queryMedPurchById")
	public @ResponseBody YzrMedPurchVo  queryMedPurchById(String purchId){
		return yzrMedPlanService.queryMedPurchById(purchId);		
	}
	
	//批量删除采购计划及采购详情
	@RequestMapping("/delMedPurch")
	public @ResponseBody Result delMedPurch(String[] list){
		yzrMedPlanService.delMedPurch(list);
		return new Result(true, "采购计划及明细删除成功！");
	}
	
	//根据状态查找采购计划
	@RequestMapping("/queryByAutditState")
	public @ResponseBody Map<String, Object> queryByAutditState(String state,int page, int rows){
		return yzrMedPlanService.queryByAutditState(state, page, rows);
	}
	
	//根据制定人查找采购计划
	@RequestMapping("/queryByPurchName")
	public @ResponseBody Map<String, Object> queryByPurchName(String purchName,int page, int rows){
		return yzrMedPlanService.queryByPurchName(purchName, page, rows);
	}
	
	//根据标题查找采购计划
	@RequestMapping("/queryByTitle")
	public @ResponseBody Map<String, Object> queryByTitle(String shuxing,int page, int rows){
		return yzrMedPlanService.queryByTitle(shuxing, page, rows);
	}
	
	//根据采购状态查找采购计划
	@RequestMapping("/queryByPurchState")
	public @ResponseBody Map<String, Object> queryByPurchState(String shuxing,int page, int rows){
		return yzrMedPlanService.queryByPurchState(shuxing, page, rows);
	}
	
	
}
